<!DOCTYPE HTML>
<html>
<head th:replace="mgr/base/head :: head('个人信息管理')"></head>
<body>
	<nav th:replace="mgr/base/nav :: active('userinfo')"></nav>
	<div id="page-wrapper" style="padding: 10px">
		<div class="container-fluid">
			<div class="row" style="padding: 5px">
				<div class="col-md-6 col-md-offset-3">
					<div class="tip" style="margin-top: 10px"></div>
					<div class="tab-content">
						<div class="tab-pane active" id="changePwdContainer">
							<form id="updateUserForm" method="post">
								<div class="form-group">
									<label for="newName">用户名</label> <input name="name"
										class="form-control" placeholder="新用户名"
										th:value="${user.name}">
								</div>
								<div class="form-group">
									<label for="newEmail">邮箱</label> <input name="email"
										class="form-control" placeholder="新邮箱"
										th:value="${user.email}">
								</div>
								<div class="form-group">
									<label for="newPwd">新密码</label> <input name="password"
										id="password" type="password" class="form-control"
										placeholder="密码">
								</div>
								<div class="form-group">
									<label for="renewPwd">再次输入新密码</label> <input type="password"
										id="renewPwd" class="form-control" placeholder="再次输入新密码">
								</div>
								<div class="form-group">
									<label for="oldPwd">旧密码</label> <input 
										id="oldPassword" type="password" class="form-control"
										placeholder="密码">
								</div>
								<div class="form-group" th:if="${otpRequired}">
									<label>动态口令</label> <input 
										id="otpCode" type="text" class="form-control"
										placeholder="动态口令">
								</div>
								<button type="button" id="updateUser" class="btn btn-default">修改信息</button>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div th:replace="base/foot_source"></div>
	<script type="text/javascript" th:src="@{/static/js/mgr/common.js}"></script>

	<script type="text/javascript" th:inline="javascript">
		/*<![CDATA[*/
		$(document).ready(function() {
			$("#updateUser").click(function() {
				var password = $("#password").val();
				if ($.trim(password) != "") {
					var renewPwd = $("#renewPwd").val();
					if (renewPwd != password) {
						error("两次密码不一致");
						return;
					}
				}
				clearTip();
				var url = basePath + "/mgr/user/update?oldPassword="+$("#oldPassword").val();
				if($("#otpCode").length > 0){
					url += '&code='+$("#otpCode").val();
				}
				var data = $("#updateUserForm").serializeObject();
				$.ajax({
					type : "post",
					url : url,
					data : JSON.stringify(data),
					dataType : "json",
					contentType : 'application/json',
					success : function(data) {
						if (data.success) {
							success(data.message);
							setTimeout(function() {
								window.location.reload()
							}, 500)
						} else {
							error(data.message);
						}
					}
				});
			});
		});
		/*]]>*/
	</script>
</body>
</html>
